package map.dircetGraph;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<List<Integer>> list = new ArrayList<>();
        boolean[] visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            list.add(new ArrayList<>());
        }
        for (int i = 0; i < k; i++) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            list.get(s - 1).add(t - 1);
        }
        bfs(visited, list, 0);
        for (boolean b : visited) {
            if (!b){
                System.out.println(-1);
                return;
            }
        }
        System.out.println(1);
    }
    public static void dfs(boolean[] visited, List<List<Integer>> graph, int x){
        if (visited[x]){
            return;
        }
        visited[x] = true;
        List<Integer> list = graph.get(x);
        for (Integer nextX : list) {
            dfs(visited, graph, nextX);
        }
    }
    public static void bfs(boolean[] visited, List<List<Integer>> graph, int x){
        Queue<Integer> q = new LinkedList<>();
        q.add(x);
        visited[x] = true;
        while (!q.isEmpty()){
            int i = q.poll();
            List<Integer> list = graph.get(i);
            for (Integer nextX : list) {
                if (!visited[nextX]){
                    q.add(nextX);
                    visited[nextX] = true;
                }
            }
        }
        List<Integer> list = graph.get(x);
        for (Integer nextX : list) {
            dfs(visited, graph, nextX);
        }
    }
}
